package pers.echo.tester;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
import pers.echo.tester.service.ITblCkqinfoService;

import javax.sql.DataSource;

//@Configuration
//@ComponentScan
//@MapperScan("pers.echo.tester.mapper")
//@PropertySource("jdbc.properties")
public class AppConfig {


    @Value("${jdbc.url}")
    String jdbcUrl;

    @Value("${jdbc.username}")
    String jdbcUsername;

    @Value("${jdbc.password}")
    String jdbcPassword;

    @Bean
    DataSource createDataSource() {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl(jdbcUrl);
        config.setUsername(jdbcUsername);
        config.setPassword(jdbcPassword);
        config.addDataSourceProperty("autoCommit", "true");
        config.addDataSourceProperty("connectionTimeout", "5");
        config.addDataSourceProperty("idleTimeout", "60");
        return new HikariDataSource(config);
    }
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

        ITblCkqinfoService tblCkqinfoService = context.getBean(ITblCkqinfoService.class);
        System.out.println(tblCkqinfoService);

        MyTest me = context.getBean(MyTest.class);
        me.run();
        System.out.println(me);

    }

}
